#include <iostream>

#include <time.h>
#include <vector>
#include <FlashSort.h>
#include <algorithm>

//Parameter order: Vector size, class size
int main(int argc, char **argv) {

  std::cout << "Call FlashSort Test!" << std::endl;
  int aVectorSize, aClassNumber, aCallNumber;   
  float aClassFactor = 0.05;
  aVectorSize = 10000000;
  double elapsed;
  struct timespec start, finish;
    
  if (argc > 1)
  {
    aVectorSize = atoi(argv[1]); 
  }
  if (argc > 2)
  {
    aClassFactor = atof(argv[2]);    
  }
    
  aClassNumber = aClassFactor * aVectorSize;
  
  float *aUnsortedArray;
  std::vector<int> aIndexVect;
  std::vector<float> bVector;
  aUnsortedArray=(float*)calloc(aVectorSize,sizeof(float)); 
  
  for (int i=0; i<aVectorSize;i++)
  {
    aIndexVect.push_back(i);
  }
  //std::random_shuffle(aIndexVect.begin(), aIndexVect.end());
  for (int i=0; i<aVectorSize;i++)
  {//thoe are perfectly distributed... for more serious test, get it random
    aUnsortedArray[aIndexVect.at(i)] = (float)(aVectorSize-i);//(float)(aVectorSize+1);     
    //aUnsortedArray[aIndexVect.at(i)] = rand()%(aVectorSize*100);
    bVector.push_back(aUnsortedArray[aIndexVect.at(i)]);
    
  }
  std::random_shuffle(bVector.begin(), bVector.end());
  aCallNumber=0;
  flashsort(aUnsortedArray, aVectorSize,aClassNumber, &aCallNumber);
  std::cout << "Call number: " << aCallNumber << std::endl;
  
  clock_gettime(CLOCK_MONOTONIC, &start);  
  std::sort(bVector.begin(), bVector.end());  
  clock_gettime(CLOCK_MONOTONIC, &finish);      
  elapsed = (finish.tv_sec - start.tv_sec);
  elapsed += (finish.tv_nsec - start.tv_nsec) / 1000000000.0;
  std::cout << "Standard Library: " << elapsed << std::endl;  
  
  // testFlashSort();
  return 0;
}